<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>改变this指向</title>
</head>

<body>
    <div id="div1">我是一个 div</div>
    <script>
        var obj1 = {
            name: 'sven'
        };
        var obj2 = {
            name: 'anne'
        };
        window.name = 'window';
        var getName = function () {
            alert(this.name);
        };
        getName(); // 输出: window
        getName.call(obj1); // 输出: sven
        getName.call(obj2); // 输出: anne
    </script>
</body>

</html>